package com.icecloud.cloud.upms.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.icecloud.cloud.upms.dao.DepartmentDao;
import com.icecloud.cloud.upms.entity.base.BaseDepartment;

@Service
@Transactional(readOnly=true)
public class DepartmentService {
	
	@Autowired
	private DepartmentDao departmentDao;
	
	public List<BaseDepartment> list(String departName,int pageNum, int pageSize){
		BaseDepartment entity = new BaseDepartment();
		if(StringUtils.isNotBlank(departName)){
			entity.setDepartName(departName);
		}
		PageHelper.startPage(pageNum, pageSize);
		return departmentDao.list(entity);
	}
	
	@Transactional(readOnly=false)
	public int save(BaseDepartment department) throws DataAccessException{
		return departmentDao.insert(department);
	}
	
	public BaseDepartment get(int departmentId){
		return departmentDao.get(departmentId);
	}
	
	public int delete(int departmentId){
		BaseDepartment entity = new BaseDepartment();
		entity.setDepartId(departmentId);
		return departmentDao.delete(entity);
	}
	
	public int update(BaseDepartment department){
		return departmentDao.update(department);
	}

}
